//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"
    str = "yangxiangnan"
var age : Double
    age = 12.34
print(age)
print("123")
print("456", terminator: "");


let min = UInt8.min
let max = UInt8.max

let decimalInteger = 17
let binaryInteger = 0b10001       // 二进制的17
let octalInteger = 0o21           // 八进制的17
let hexadecimalInteger = 0x11


let ee = 1.25e2
let eee = 1.25e-2

//16进制指数表示
let xx = 0xFp2 //表示 15 × 2^2，等于 60.0。
let xxx = 0xFp-2 //表示 15 × 2^-2，等于 3.75。

let paddedDouble = 000123.456
let oneMillion = 1_000_000
let justOverOneMillion = 1_000_000.000_000_1

//类型转换
let twoThousand: UInt16 = 2_000
let one: UInt8 = 1
let twoThousandAndOne = twoThousand + UInt16(one)

let three = 3
let pointOneFourOneFiveNine = 0.14159
let pi = Double(three) + pointOneFourOneFiveNine


//类型别名

typealias AudioSample = UInt16
let audiomin = AudioSample.min


//bool
let orangesAreOrange = true
let turnipsAreDelicious = false

if orangesAreOrange{
    print("13")
}else{
    print("35")
}

//元组：把多个值组合成一个复合值 任意顺序的类型组合成一个元组
let http404Error = (405, "Not Found")
let (statusCode, statusMessage) = http404Error
print("The status code is \(statusMessage)")
//只取一部分
let (justTheStatusCode, _) = http404Error
//根据下标获取
print("The status code is \(http404Error.0)")

let http200Status = (statusCode: 200, description: "OK")
print("The status code is \(http200Status.statusCode)")
print("The status message is \(http200Status.description)")

//可选值   nil表示值缺失，而不是对象不存在
var serverResponseCode: Int? = 404
serverResponseCode = nil

var surveyAnswer: String?
surveyAnswer = "123"
//强制解析
if surveyAnswer != nil {
    print("convertedNumber has an integer value of \(surveyAnswer!).")//强制解析
}

//可选绑定
let possibleNumber = "123"
if let actualNumber = Int(possibleNumber) {
    print("\'\(possibleNumber)\' has an integer value of \(actualNumber)")
} else {
    print("\'\(possibleNumber)\' could not be converted to an integer")
}


//隐式解析可选类型

































